package com.zhongwang.mms.module.tool.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.tool.model.AccToolStatisModel;
import com.zhongwang.mms.module.tool.service.AccToolStatisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class AccToolStatisController  extends BaseController {
    @Autowired
    private AccToolStatisService accToolStatisService;
    /**
     * 页面
     *
     * @return 页面路径
     */
    @GetMapping("/tool/statistic/page")
    @RequiresPermissions({"drive:statistics:view"})
    public String linkePage() {
        return "tool/statistic/list";
    }

    /**
     * 新增-上传附件
     * @param file
     * @param statisDate
     * @param statisDetail
     * @param statisType
     * @return
     */
    @ResponseBody
    @PostMapping("/tool/statistic/upload")
    @RequiresPermissions({"drive:statistics:add"})
    public JsonResult uploadFile(@RequestParam("file") MultipartFile[] file,@RequestParam("statisDate") String statisDate,@RequestParam("statisDetail") String statisDetail,@RequestParam("statisType") String statisType) {
        return jsonResult(accToolStatisService.saveFile(file,statisDate,statisDetail,statisType));
    }


    /**
     * 查询设备台账统计信息
     *
     * @param model 设备台账统计参数
     * @return EquipmentModel
     */
    @ResponseBody
    @PostMapping("/tool/statistic/list")
    @RequiresPermissions({"drive:statistics:view"})
    public JsonResult selectList(AccToolStatisModel model) {
        startPage();
        return jsonResult(accToolStatisService.selectAccToolStatisList(model));

    }

    /**
     * 删除
     * @param id 主键id
     * @return
     */
    @PostMapping("/tool/statistic/del")
    @ResponseBody
    @RequiresPermissions({"drive:statistics:del"})
    public JsonResult deleteByPrimaryKey(Integer id){
        JsonResult jsonResult = new JsonResult();
        Integer flg=accToolStatisService.del(id);
        if (flg==1) {
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除成功");
        }
        else{
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除失败");
        }
        return jsonResult;
    }

    /***
     * 编辑设备台账统计
     * @param file
     * @param statisDate
     * @param statisDetail
     * @param statisId
     * @return
     */
    @ResponseBody
    @PostMapping("/tool/statistic/edit")
    @RequiresPermissions({"drive:statistics:edit"})
    public JsonResult editUploadFile(@RequestParam("file") MultipartFile[] file,@RequestParam("statisDate") String statisDate,@RequestParam("statisDetail") String statisDetail,@RequestParam("statisId") Integer statisId) {
        return jsonResult(accToolStatisService.editFile(file,statisDate,statisDetail,statisId));
    }
}
